package cn.wolfcode.crm.web.controller;

import cn.wolfcode.crm.domain.Salary;
import cn.wolfcode.crm.domain.SystemDictionaryItem;
import cn.wolfcode.crm.query.SalaryQuery;
import cn.wolfcode.crm.service.ISalaryService;
import cn.wolfcode.crm.service.IEmployeeService;
import cn.wolfcode.crm.service.ISystemDictionaryItemService;
import cn.wolfcode.crm.service.ISystemDictionaryService;
import cn.wolfcode.crm.util.JsonResult;
import com.github.pagehelper.PageInfo;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/salary")
public class SalaryController {
    @Autowired
    private ISalaryService salaryService;
    @Autowired
    private IEmployeeService employeeService;
    @Autowired
    private ISystemDictionaryItemService systemDictionaryItemService;


    @RequestMapping("/list")
    public String List(Model model, @ModelAttribute("qo")SalaryQuery qo) {//创建qo对象
     
        //职业下拉框的
        List<SystemDictionaryItem> size = systemDictionaryItemService.selectByDicSn("size");
        model.addAttribute("size",size);

        model.addAttribute("employees",employeeService.listAll());
        
        
        PageInfo pageInfo = salaryService.query(qo);
        model.addAttribute("result", pageInfo);
        return "salary/list";
    }




    @RequestMapping("/saveOrUpdate")
    @RequiresPermissions(value = {"saveOrUpdate:list","部门保存/更新"}, logical=Logical.OR)//or只要有一个就可以运行
    @ResponseBody
    public JsonResult saveOrUpdate(Salary salary) {

        if (salary.getId() == null) {
            salaryService.save(salary);
        } else {
            salaryService.update(salary);
        }
        return new JsonResult();

    }

}
